package IOStreamTest.FileStream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

/*
减少硬盘和内存的交互，提高程序的执行效率
    往byte[]数组当中读
 */
public class FileInputStreamTest2 {
    public static void main(String[] args){
        FileInputStream fis = null;
        try{
            fis = new FileInputStream("src\\MapTest\\HashMapTest1.java");
            //准备一个byte数组
            byte[] bytes = new byte[1024];
            //将读取到数据放入byte[]中
            int num = 0;
            while((num = fis.read(bytes)) != -1){
                //将文件读取内容打印到控制台
                System.out.print(new String(bytes,0,num));
            }
        }catch(FileNotFoundException f){
            f.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally{
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
